package com.frxuexi.mynews

import android.app.Application
import android.content.Context
import android.util.Log
import com.alibaba.android.arouter.launcher.ARouter
import com.tencent.bugly.crashreport.CrashReport
import com.tencent.mmkv.MMKV
import com.umeng.commonsdk.UMConfigure
import com.umeng.message.PushAgent
import com.umeng.message.api.UPushRegisterCallback
import com.umeng.socialize.PlatformConfig


class App:Application() {

    companion object{
        @JvmField
        var context:Context?=null


    }



    override fun onCreate() {
        super.onCreate()
        ARouter.init(this)
        ARouter.openLog()
        ARouter.openDebug()

        //初始化
        MMKV.initialize(this)
        getContext()

        CrashReport.initCrashReport(getApplicationContext(), "5731bb3684", false);

        //QQ官方sdk授权
//        Tencent.setIsPermissionGranted(true);
        UMConfigure.init(this,"6667a79e940d5a4c49682d01"
            ,"umeng",UMConfigure.DEVICE_TYPE_PHONE,"");

        // QQ设置
        PlatformConfig.setQQZone("101830139","5d63ae8858f1caab67715ccd6c18d7a5");
        PlatformConfig.setQQFileProvider("com.tencent.sample2.fileprovider");

        //日志开关
        UMConfigure.setLogEnabled(true);
        //获取消息推送实例
        //获取消息推送实例
        val pushAgent = PushAgent.getInstance(context)
        //注册推送服务，每次调用register方法都会回调该接口
        //注册推送服务，每次调用register方法都会回调该接口
        pushAgent.register(object : UPushRegisterCallback {
            override fun onSuccess(deviceToken: String) {
                //注册成功会返回deviceToken deviceToken是推送消息的唯一标志
                Log.i("===", "注册成功 deviceToken:$deviceToken")
            }

            override fun onFailure(errCode: String, errDesc: String) {
                Log.e("===", "注册失败 code:$errCode, desc:$errDesc")
            }
        })
    }

    fun getContext(){
        context=this
    }
}